package com.erification.web.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.erification.web.model.User;
import com.erification.web.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@Controller
public class LoginAction extends ActionSupport {
	@Resource
	private UserService userService;
	private User user;
	private String message;
	
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	@Override
	public String execute() throws Exception {
		message = userService.validate(user.getUsername(), user.getPassword());
		if(message.equals("登录成功")){
			ActionContext.getContext().getSession().put("username", user.getUsername());
			return SUCCESS;
		} else return ERROR;
	}
	
}
